﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

namespace FancyIdea.PingShui.Core.Util
{
    public class CommUtil
    {
        public static DataTable ConvertEnumToDataTable(Type source)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("TEXT");
            dt.Columns.Add("VALUE");

            foreach (string name in Enum.GetNames(source))
            {
                DataRow dr = dt.Rows.Add();
                dr[0] = name;
                dr[1] = (int)Enum.Parse(source, name);
            }
            return dt;
        }

        public static int GetValueByName(Type t, string name)
        {
            return Convert.ToInt32(Enum.Parse(t, name));
        }
    }
}